#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>

typedef struct STU
{
	int iId;
	char caName[32];
	float fScore;
}STU;

void print(const STU *stu, int count)
{
	if (NULL == stu || count <= 0)
	{
		return;
	}
	int i = 0;
	for (; i<count; i++)
	{
		printf("id:%d, name:%s, score:%.1f\n", stu[i].iId
			   , stu[i].caName, stu[i].fScore);
	}
}

int findMaxByScore(const STU *stu, int count)
{
	int max = -1;
	if (NULL != stu && count > 0)
	{
		max = 0;
	   	int i = 0;
		for (i=1; i<count; i++)
		{
			if (stu[max].fScore < stu[i].fScore)
			{
				max = i;
			}
		}	
	}
	return max;
}

int main(void)
{
	STU stu[5] = {{1001, "jack", 89}
	              , {1002, "rose", 21}
	              , {1003, "tony", 99}
	              , {1004, "peter", 66}
	              , {1005, "jimy", 44}};

	print(stu, 5);

	printf("-------------------------\n\n");
	int index = findMaxByScore(stu, 5);
	if (-1 != index)
	{
		printf("id:%d, name:%s, score:%.1f\n", stu[index].iId
			   , stu[index].caName, stu[index].fScore);
	}


	return 0;
}
